<template>
  <view class="content">
    <view class="product-content">
      <ScrollList :finished="isFinished" :loading="isLoading" :show-empty="isFinished && !list?.length" style="height: calc(100vh - 100rpx); width: calc(100vw - 32rpx)" @load="load" @refresh="reset">
        <div class="product-grid">
          <GoodItem v-for="(product, index) in list" :key="index" class="product-card" :product="product" />
        </div>
      </ScrollList>
    </view>
  </view>
</template>

<script setup lang="ts">
import ScrollList from '@/components/scroll-list/scroll-list.vue';
import { usePagination } from '@/hooks/usePagination';
import GoodItem from '@/components/good/GoodItem.vue';
import { onMounted, ref } from 'vue';
import { getTheItemsInMyCollection } from '@/api/searchApi';
import { onShow } from "@dcloudio/uni-app";

const props = defineProps({
  keyword: {
    type: String,
    default: '',
  },
});
const designerOrderBy = ref('orders');

const { list, isLoading, load, reset, isFinished } = usePagination(queryProducts);
function queryProducts(page = 1) {
  const data = {
    page: page,
    orderBy: designerOrderBy.value,
    keyword: props.keyword,
  };
  return getTheItemsInMyCollection(data);
}

onMounted(() => {
  reset();
});
onShow(() => {
  reset();
})
</script>
<style scoped lang="scss">
.content {
  width: calc(100vw);
  box-sizing: border-box;
  .filter-nav {
    display: flex;
    justify-content: space-between;
    height: 64rpx;
    background: #ffffff;
    border-radius: 0rpx 0rpx 0rpx 0rpx;
    padding: 0 32rpx;
    border-top: 1rpx solid #e4e4e4;
    box-sizing: border-box;
    .filter-nav-item {
      display: flex;
      align-items: center;
      height: 64rpx;
      font-weight: 400;
      font-size: 24rpx;
      line-height: 64rpx;
      text-align: left;
      color: #6f6f6f;
      &.active {
        color: #f25a27;
      }
      image {
        width: 10rpx;
        height: 14rpx;
        margin-left: 8rpx;
      }
      .sort-icon {
        height: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
      }
    }
  }
}

.product-content {
  background: #f3f7f8;
  padding: 16rpx;
  border-radius: 16rpx 16rpx 16rpx 16rpx;
}
.product-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  grid-gap: 16rpx;
  padding: 24rpx 16rpx;
  background: #fff;
}

.designer-grid {
  display: grid;
  grid-template-columns: 1fr;
  grid-gap: 16rpx;
  padding: 24rpx 0;
  background: #f3f7f8;
}
</style>

<style lang="scss">
.wd-tabs-custom {
  width: auto !important;
}
</style>
